/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.intime.util;

import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

/**
 * Classe que gerência as sessões com a base de dados
 * através do uso hibernate.
 * 
 * @version 1.0
 * @author Valdigleis
 */
public class HibernateUtil {
    
    private static final SessionFactory sessionfactory;
    
    public static final String HIBERNATE_SESSION = "hibernate_session";
    
    static{
        try {
            
            System.out.println("Tentando abrir uma sessão");
            Configuration configuration = new Configuration().configure();
            ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
            sessionfactory = configuration.buildSessionFactory(serviceRegistry);
            System.out.println("Sessão aberta!");
            
        } catch (Exception e) {
            System.out.println("Erro ao iniciar a Sessão ao iniciar a sessão \n" + e);
            throw new ExceptionInInitializerError(e);
        }
        
    }

    public static SessionFactory getSessionfactory() {
        return sessionfactory;
    }
}
